Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Reroll keys #2058

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

feat: Reroll keys #2058

wants to merge 21 commits into from

Conversation

ygorhiroshi
Copy link
Contributor

@ygorhiroshi ygorhiroshi commented Sep 1, 2024

What does this PR do?

Implements a new feature to Reroll keys.

Fixes #2050

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Create a new api
  • Create a new key
  • View key details
  • Click on the button Reroll Key and a Dialog will show up
  • Select an optional delay period (default is 1h as agreed with @chronark)
  • Click on the Reroll Key action button
  • Wait for the process to finish
  • The user must be redirect to the new key details page.
  • Check if the key value has changed.

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Here a link of the new feature recording

Reroll Key Dialog

image

Reroll Key Dialog - delay period options

image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new RerollKey component for regenerating API keys directly from the Settings Page.
    • Enhanced API key management with options for immediate or delayed expiration of old keys.
    • Improved user experience with toast notifications for success and error states during key operations.
    • Enhanced router functionality to update key deletion timestamps and encryption status.
  • Bug Fixes

    • Improved handling of API key expiration and deletion timestamps to ensure accurate updates.

Copy link

changeset-bot bot commented Sep 1, 2024

⚠️ No Changeset found

Latest commit: 3a28590

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ygorhiroshi
❌ hiroasano
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

vercel bot commented Sep 1, 2024

@hiroasano is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 1, 2024

Walkthrough

Walkthrough

The changes introduce a feature that enables users to reroll API keys directly from the key detail and settings pages in the dashboard. This includes the implementation of the RerollKey component, which allows users to generate a new key while expiring the old one based on user-defined expiration options. Additionally, new TRPC procedures support these functionalities, enhancing the overall API key management process.

Changes

Files Change Summary
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/settings/page.tsx
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/settings/reroll-key.tsx
Introduced the RerollKey component in SettingsPage for rerolling API keys, enhancing the user interface for key management.
apps/dashboard/lib/trpc/routers/key/updateEncrypted.ts Defined updateKeyEncrypted TRPC procedure for updating encrypted keys, including validation and audit logging.
apps/dashboard/lib/trpc/routers/index.ts Added updateKeyDeletedAt and updateKeyEncrypted functions to the router, enhancing key management capabilities and renamed a permission-related function.

Assessment against linked issues

Objective Addressed Explanation
Reroll a key from the UI (related to #2050)
Combine key creation and deletion into a smoother process (related to #2050)
Allow user to select expiration time when rerolling a key (related to #2050)

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Sep 1, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/reroll-key.tsx (2)

178-195: Consider replacing the switch statement with an object lookup.

The getDateFromExpirationOption function is correctly implemented. However, consider replacing the switch statement with an object lookup for better readability and performance:

const EXPIRATION_OPTIONS_MAP: Record<string, number> = {
  '5m': 5 * 60 * 1000,
  '30m': 30 * 60 * 1000,
  '1h': 1 * 60 * 60 * 1000,
  '6h': 6 * 60 * 60 * 1000,
  '24h': 1 * 24 * 60 * 60 * 1000,
  '7d': 7 * 24 * 60 * 60 * 1000,
};

function getDateFromExpirationOption(option: string) {
  const delay = EXPIRATION_OPTIONS_MAP[option] || 0;
  return new Date(Date.now() + delay);
}

119-119: Simplify the conditional expression.

The static analysis tool correctly suggests removing the unnecessary ternary operator. Simplify the code by directly assigning the result of the comparison:

- enabled: values.expiresIn === "now" ? false : true,
+ enabled: values.expiresIn !== "now",
Tools
Biome

[error] 119-119: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fde3d83 and 39c387a.

Files selected for processing (4)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/reroll-key.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Additional context used
Biome
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/reroll-key.tsx

[error] 119-119: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

Additional comments not posted (4)
apps/dashboard/lib/trpc/routers/index.ts (1)

69-69: LGTM!

The code changes are approved.

apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/reroll-key.tsx (1)

59-176: LGTM!

The RerollKey component is well-implemented and follows best practices:

  • It uses well-known libraries and components for form handling, validation, API calls, navigation, dialog state management, and UI.
  • The form handling and validation are implemented correctly using react-hook-form and zod.
  • The API calls are handled correctly with success and error cases using trpc.
  • The navigation and dialog state management are implemented correctly using next/navigation and useState.
  • The UI is implemented using reusable components from @/components/ui/*.
  • The loading and error states are handled correctly using Loading component and toast notifications.
Tools
Biome

[error] 119-119: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (2)

27-27: LGTM!

The new import statement for the RerollKey component is syntactically correct and aligns with the feature implementation.


166-179: Excellent integration of the RerollKey component!

The code segment properly integrates the RerollKey component within a new div element, alongside a link to the key settings. The necessary props (trigger, currentKey, and apiId) are correctly passed to the RerollKey component.

apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 39c387a and 85fb3a6.

Files selected for processing (1)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 85fb3a6 and 6fc4af1.

Files selected for processing (1)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts

Copy link
Collaborator

@chronark chronark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use it in the UI, I don't see the new key unfortunately.

Also added a few comments in the code

@ygorhiroshi
Copy link
Contributor Author

When I use it in the UI, I don't see the new key unfortunately.

I believe you see the new key. it's not showing the old one because we're setting the deletedAt and the query filters to not show a key that has it set.

@chronark
Copy link
Collaborator

chronark commented Sep 4, 2024

I believe you see the new key. it's not showing the old one because we're setting the deletedAt and the query filters to not show a key that has it set.

Sorry, let me clarify, I meant the user is never shown the new secret, similar to how we show it when a new key is generated

CleanShot 2024-09-04 at 08 59 54@2x

In the modal, we should display the new key after they rerolled it. We don't need the curl command though

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6fc4af1 and 876beb9.

Files selected for processing (4)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (2 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (2 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts
Additional comments not posted (7)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (2)

17-17: LGTM!

The code changes are approved.


71-71: LGTM!

The code changes are approved.

apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (5)

1-41: LGTM!

The imports and component props are correctly used and typed.


53-59: LGTM!

The form schema and component state are correctly defined and used.


69-90: LGTM!

The tRPC mutations are correctly defined and used, and the onSuccess and onError callbacks are correctly used to handle the response.


92-112: LGTM!

The onSubmit function correctly creates a new key, calculates the expiration date, and expires the old key. The success and error cases are correctly handled using the toast library.


114-167: LGTM!

The component rendering is correctly implemented using various UI components, the useForm hook, and the onSubmit function.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 876beb9 and 58e0e48.

Files selected for processing (5)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx
  • apps/dashboard/lib/trpc/routers/index.ts
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58e0e48 and 16513bc.

Files selected for processing (3)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (4 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/key/create.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx
Additional context used
Biome
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx

[error] 4-5: Some named imports are only used as types.

This import is only used as a type.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

Additional comments not posted (4)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (3)

17-17: Import Statement for RerollKey Approved

The import statement correctly brings in the RerollKey component necessary for the new feature.


75-75: Verify Type Casting and Component Placement

The RerollKey component is integrated into the SettingsPage. However, verify the following:

  • The type casting of apiKey to Key & { roles: []}. Ensure this casting aligns with the expected types and does not introduce potential type errors.
  • The placement of the component within the JSX structure to ensure it is logical and consistent with UI design principles.

35-38: Updates to the with Object Approved

The updates to the with object in the database query enhance security and identification features. However, verify the following:

  • Ensure that these properties (encrypted, identity, roles, permissions) are correctly used throughout the application.
  • Check for any potential performance impacts due to these additions.
apps/dashboard/lib/trpc/routers/key/create.ts (1)

36-36: Addition of identityId Approved

The new optional field identityId is correctly added to the input schema and reflected in the mutation logic. However, verify the following:

  • Ensure that the optional nature of identityId does not introduce any unintended side effects in the mutation logic.
  • Check for any potential issues related to data consistency or validation when identityId is not provided.

Also applies to: 96-96

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16513bc and 1438410.

Files selected for processing (4)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-confirmation-dialog.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-new-key-dialog.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1438410 and ce7cd11.

Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-confirmation-dialog.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-new-key-dialog.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-confirmation-dialog.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-new-key-dialog.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ce7cd11 and 18fa6e7.

Files selected for processing (8)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-confirmation-dialog.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-new-key-dialog.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/create.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx
Files skipped from review as they are similar to previous changes (6)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-confirmation-dialog.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-key.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/reroll-new-key-dialog.tsx
  • apps/dashboard/lib/trpc/routers/index.ts
  • apps/dashboard/lib/trpc/routers/key/create.ts
  • apps/dashboard/lib/trpc/routers/key/updateDeletedAt.ts
Additional comments not posted (3)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/page.tsx (3)

11-11: New component import: RerollKey.

The import of the RerollKey component is correctly placed among other related component imports. This organization helps maintain clarity and consistency in the file structure.


80-84: Integration of the RerollKey component.

The RerollKey component is well-integrated into the JSX structure of the SettingsPage. The props passed to the component, including apiId, apiKey, and lastUsed, are appropriate for its functionality. However, the casting of key to Key & { roles: [] } should be reviewed to ensure it accurately reflects the expected data structure and does not introduce type mismatches.

Run the following script to verify the type casting for accuracy:

Verification successful

Review the type casting for apiKey in RerollKey.

The casting of key to Key & { roles: [] } in the RerollKey component appears to be a workaround to meet the component's prop requirements. This approach is acceptable as long as the component can handle the empty roles array appropriately. If further verification is needed, consider reviewing the schema.keys structure to ensure the casting aligns with the expected data model.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the type casting for the `apiKey` prop in the `RerollKey` component.

# Test: Search for the type definition of `Key` and its usage. Expect: Consistency with the casting.
rg --type typescript -A 5 $'type Key'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the type casting for the `apiKey` prop in the `RerollKey` component.

# Test: Search for the type definition of `Key` and its usage. Expect: Consistency with the casting.
rg --type ts -A 5 $'type Key'

Length of output: 5690


36-39: Enhanced security and identification features in the with object.

The expansion of the with object to include encrypted, identity, roles, and permissions is a positive change, likely supporting the new RerollKey functionality. Ensure that these properties are properly utilized in the reroll process and that their integration is secure and efficient.

Run the following script to verify the integration of these properties in the reroll functionality:

Copy link

vercel bot commented Sep 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 0:34am
planetfall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 0:34am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 0:34am
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 0:34am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 0:34am

Copy link
Collaborator

@perkinsjr perkinsjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When rerolling a key with the selection time of "now"

It causes an error because you are sending null down for deleted at, and because at that point you already rerolled the key. It causes the original key to be valid and the new key to also be valid.

We need to ensure that if one part of the reroll fails, we handle this appropriately in the code and restore correctly.

For example:

  1. New key gets created, old key does not get deleted correctly. We need to ensure the new key is not valid, and the old key can be accessed.
  2. New key fails to be created do not start the processes of deleting a key.

image

@ygorhiroshi
Copy link
Contributor Author

@chronark @perkinsjr with this last commit I believe the PR is ready to be reviewed.
Please let me know if there is anything missing.

Copy link
Collaborator

@perkinsjr perkinsjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For keys that don't expire NOW you cannot set them to deleted. If you set the date to deleted it will cause them to be unusable.

We have a column named "expires" which would make more sense, as that will automatically set the deleted at, at the correct time.

Otherwise we would need to change the way the API works.

@chronark chronark self-assigned this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reroll keys
5 participants